package org.example.mytest.newControler;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.mytest.newMapper.GoodsMapper;
import org.example.mytest.newentity.goods;
import org.example.mytest.newentity.users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/goods")
public class GoodsControler
{
    @Autowired
    private GoodsMapper goodsMapper;
    @GetMapping("/query0")
    public List query2() {
        List<goods> list = goodsMapper.selectList(null);
        return list;
    }
    @GetMapping("/findByPage/{page}/{size}")
    public IPage findByPage(@PathVariable("page") Integer page,
                            @PathVariable("size") Integer size){
        //设置起始值及每页数
        Page<goods> pages = new Page<>(page,size);
        IPage iPage=goodsMapper.selectPage(pages,null);
        System.out.println(iPage);
        return iPage;
    }
    @CrossOrigin
    @DeleteMapping("/delete1/{userId}")
    public int delete1(@PathVariable("userId") Integer userId){
        int row=goodsMapper.deleteById(userId);
        return row;
    }
    @CrossOrigin
    @GetMapping("/selectById/{userId}")
    public goods selectById(@PathVariable("userId")Integer userId)
    {
        return goodsMapper.selectById(userId);
    }
    @CrossOrigin
    @PutMapping("/update2")
    public int update2(@RequestBody goods uses){
        int result = goodsMapper.updateById(uses);
        return result;
    }


}